package com.voxel.sense.infomsg.module.firm.details.device;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.example.com.common.view.recycler.RecyclerAdapter;
import com.voxel.sense.infomsg.R;

import java.util.List;

import cyy.example.com.facotry.model.api.response.FirmDeviceInfoBean;

public class FirmDevicesAdapter extends RecyclerAdapter<FirmDeviceInfoBean> {


  @Override
  protected int getItemViewType(int position, FirmDeviceInfoBean companyDataBean) {
    return R.layout.item_recycle_device_firm;
  }

  public FirmDevicesAdapter(AdapterListener listener) {
    super(listener);
  }

  public FirmDevicesAdapter(List list, AdapterListener listener) {
    super(list, listener);
  }

  @Override
  protected ViewHolder onCreateViewHolder(View root, int viewType) {
    return new FirmDevicesAdapter.Viewholder(root);
  }

  static class Viewholder extends RecyclerAdapter.ViewHolder<FirmDeviceInfoBean> {

    TextView mStanceDesc;//检测站位
    TextView mDevicesNum;//仪器名称
    TextView mDevicesName;//仪器编号
    TextView mDeviceParam;//检测参数
    TextView mDevicePeriod;//保修期

    private final Context mContext;
    private Viewholder(View itemView) {
      super(itemView);
      mContext = itemView.getContext();

      mStanceDesc = itemView.findViewById(R.id.stance_desc);//检测站位
      mDevicesName = itemView.findViewById(R.id.device_name);//仪器名称
      mDevicesNum = itemView.findViewById(R.id.device_num);//仪器编号
      mDeviceParam = itemView.findViewById(R.id.device_param);//检测参数
      mDevicePeriod = itemView.findViewById(R.id.device_warranty_period);//保修期
    }

    @Override
    protected void onBind(final FirmDeviceInfoBean bean) {
      //由于区地址右边有padding，当没有数据时隐藏，以免影响到其它布局的位置
      refreshData(bean);

    }

    private void refreshData(FirmDeviceInfoBean bean) {

      mStanceDesc.setText(bean.getWatchName());
      mDevicesName.setText(bean.getDevName());
      mDevicesNum.setText(bean.getDevNumber());
      mDeviceParam.setText(bean.getDevMonitorParam());
      mDevicePeriod.setText(bean.getDevProtectTime()+"年");
    }

  }
}
